/*
 * copyright (c) 2013 Blaise-Florentin Collin
 *
 * This file is part of astroDCAM.
 *
 * AstroAviBrowser is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License v3
 * as published by the Free Software Foundation
 *
 * AstroAviBrowser is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * v3 along with AstroAviBrowser; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA
 */

///
/// \file dc1394camera.hpp
///
/// \brief Object wrapper for the dc1394 api (camera part) (headers)
///

#ifndef _DC1394CAMERA_HPP_
#define _DC1394CAMERA_HPP_

// C++ includes
#include <string>
#include <vector>

// libdc1394 includes
#include <dc1394/dc1394.h>
#include <dc1394/camera.h>
#include <dc1394/video.h>

// C++ app includes
#include "dc1394error.hpp"
#include "frame.hpp"

///
/// \def Number of frames buffered in the camera queue
///
#define _CAMERA_BUFFERS_	4

///
/// \enum dc1394color
///
/// \brief Color plans available on IIDC
typedef enum {
   NONE,
   MONO8,
   MONO16,
   RGB24,
   YUV444,
   YUV422,
   YUV411
} dc1394plan;

///
/// \class dc1394rate
///
/// \brief IIDC frame rates
///
class dc1394rate {
   public :
      int index; ///< Frame rate number
      std::string name; ///< Frame description
      int value; ///< Interval between 2 frames (ms)
};

///
/// \class dc1394mode
///
/// \brief IIDC video mode
///
class dc1394mode {
   public :
      int index; ///< Mode number
      std::string name; ///< Mode description
      int width; ///< Frame width
      int height; ///< Frame height
      dc1394plan plan; ///< Color coding scheme
};

extern const std::vector<dc1394mode> dc1394modes; ///< All the IIDC available video modes

///
/// \class dc1394cameraId
///
/// \brief Used for camera identification
///
class dc1394cameraId {
   public :
      std::string cameraVendor; ///< Camera vendor string
      std::string cameraModel; ///< Camera model string
      uint64_t cameraGuid; ///< Camera numeric id
};

///
/// \class dc1394camera
///
/// \brief Object wrapper for the dc1394 api (camera part)
///
class dc1394camera {
   public :
      /// Main constructor
      dc1394camera(dc1394_t* bus, uint64_t guid);
      /// Main destructor
      ~dc1394camera();
      /// Is the camera ready ?
      bool isReady() { return(camera_handler!=NULL); }
      /// Get supported modes
      std::vector<dc1394mode> getSupportedModes();
      /// Get supported frame rates
      std::vector<dc1394rate> getSupportedRates();
      /// Set the mode
      dc1394error setMode(int m);
      /// Set the frame rate
      dc1394error setRate(int m);
      /// Get the current mode
      dc1394mode getMode();
      /// Get the current frame rate
      dc1394rate getRate();
      /// Get the current stream state (true : streaming, false : not streaming)
      bool getStreamState();

      /// Start capture
      dc1394error startCapture();
      /// Stop capture
      dc1394error stopCapture();
      /// Grab a frame
      frame* grabFrame();
   private :
      bool streamOn; ///< is the camera streaming datas ?
      dc1394_t* bus_handler; ///< The camera's bus handler
      dc1394camera_t* camera_handler; ///< The camera's handler
      dc1394video_mode_t current_mode; ///< The camera's current video mode
      dc1394framerate_t current_rate; ///< the current camera's frame rate
};

#endif
